import gi
gi.require_version("Gtk", "4.0")
gi.require_version("GtkSource", "5")

from gi.repository import Gtk, GtkSource

def on_activate(app):
    win = Gtk.ApplicationWindow(application=app)
    win.set_default_size(600,400)

    scroll = Gtk.ScrolledWindow()
    win.set_child(scroll)        
    view = GtkSource.View.new()
    scroll.set_child(view)
    buf = view.get_buffer()
    provider = GtkSource.CompletionWords.new("main")
    provider.register(buf)
    completion = view.get_completion()
    completion.add_provider(provider)

    win.present()

app = Gtk.Application()
app.connect('activate', on_activate)
app.run(None)